home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Devices / NuBus⁄Slot Manager / ROM Build⁄Download 3.2.4 / CRCPatch folder / CRCPatch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-25  |  3.3 KB  |  113 lines  |  [TEXT/MPS ]

  1. /**********************************************************************
  2.  *
  3.  * Copyright Apple Computer, Inc. 1986,1992, 1995
  4.  * All Rights Reserved
  5.  *
  6.  *    Description:     This program reads code segment 1 from a specified
  7.  *                    Resource file, calculates the crc value, then
  8.  *                    patches the CRC value into the segment.  Run this 
  9.  *                    tool after assembling and linking the declaration 
  10.  *                    ROM file. Next, run the Data tool to transfer the 
  11.  *                    CODE 1 segment into a data file.  The data file can
  12.  *                    then be down-loaded into a ROM programmer.
  13.  *
  14.  *    Calling syntax: crcPatch  filename
  15.  *
  16.  *    Written:         July 30, 1986.
  17.  *
  18.  *    Modified:       9/16/92.  
  19.  *                    • Changed this header to be more readable.
  20.  *                    • Fixed bug that caused possible bus error in 
  21.  *                      32 bit mode when skipping over first 4 bytes of 
  22.  *                      the resource header
  23.  *
  24.  **********************************************************************/
  25.                         
  26.  
  27. #include <stdio.h>
  28. #include <types.h>
  29. #include <osutils.h>
  30. #include <files.h>
  31. #include <resources.h>
  32. #include <memory.h>
  33. #include <errno.h>
  34.  
  35.  
  36. pascal void debugger() extern 0xa9ff;
  37.  
  38.  
  39. pascal void _CalcCRC (SizeCode,CodePtr,crc)
  40. long        SizeCode;
  41. Ptr            CodePtr;
  42. long        *crc;
  43. extern;
  44.  
  45. /******************************************************************
  46.     Main
  47. *******************************************************************/
  48. main(argc,argv)
  49.  
  50. int      argc;
  51. char  *argv[];
  52.  
  53. {
  54.   short        refnum;
  55.   Handle    CodeHandle;        /* Handle to code resource */
  56.   short        IOR;            /* IO Result */
  57.   long        SizeCode;        /* Size of the code */
  58.   Ptr        CodePtr;        /* Pointer to the code */
  59.   long        crc;            /* the crc value */
  60.         
  61.   if (argc == 1)
  62.     {
  63.       fprintf(stderr,"### ERROR : No input file specified.\n");
  64.       fprintf(stderr,"### SYNTAX: crcPatch  filename\n");
  65.       fprintf(stderr,"### DSCRPT: Calculate and patch the crc value to code segment 1.\n");
  66.     }
  67.   else if (argc != 2)
  68.     {
  69.       fprintf(stderr,"### ERROR : Wrong number of parameters specified.\n");
  70.       fprintf(stderr,"### SYNTAX: crcPatch  filename\n");
  71.       fprintf(stderr,"### DSCRPT: Calculate and patch the crc value to code segment 1.\n");
  72.     }
  73.   else
  74.     {
  75.       refnum = openresfile(argv[1]);
  76.       if (refnum < 0 )
  77.         fprintf(stderr,"### ERROR : Resource file: %s can't be opened. err = %d.\n",argv[1],refnum);
  78.       else
  79.         {
  80.            CodeHandle = GetResource('CODE',1);
  81.            HLock(CodeHandle);
  82.            IOR = ResError();
  83.            if (IOR != 0)
  84.              fprintf(stderr,"### ERROR : Code resource not available. Err = %d\n",IOR);
  85.            else
  86.              {
  87.               /* SizeCode = SizeResource(CodeHandle);*/
  88.                SizeCode = GetHandleSize(CodeHandle);
  89.                SizeCode = SizeCode - 4;                                        /* Skip first 4 bytes (Resource header) */               
  90.                CodePtr = ((Ptr)*CodeHandle) + 4;                            /* Skip first 4 bytes (Resource header) */
  91.         
  92.                _CalcCRC(SizeCode,CodePtr,&crc);                                /* Calc and patch the crc value */
  93.  
  94.                ChangedResource(CodeHandle);
  95.                IOR = ResError();
  96.                if (IOR != 0)
  97.                  fprintf(stderr,"### ERROR : ChangedResource. Err = %d\n",IOR);
  98.  
  99.                WriteResource(CodeHandle);
  100.                IOR = ResError();
  101.                if (IOR != 0)
  102.                  fprintf(stderr,"### ERROR : WriteResource. Err = %d\n",IOR);
  103.  
  104.                CloseResFile(refnum);
  105.                IOR = ResError();
  106.                if (IOR != 0)
  107.                  fprintf(stderr,"### ERROR : CloseResFile. Err = %d\n",IOR);
  108.              }
  109.         }
  110.     }
  111. }
  112.  
  113.